package com.nulldev.util.web.HttpServer3.extensions.nCaptcha.captchas.obftext;

import java.awt.image.BufferedImage;

import com.nulldev.util.VariableAPI.StringsUtil;
import com.nulldev.util.data.Images.ImageUtil;
import com.nulldev.util.data.Images.legacy.TextObf;
import com.nulldev.util.data.Images.legacy.TextObf.ObfuscationMethod;
import com.nulldev.util.data.Sets.DataSet;
import com.nulldev.util.web.HttpServer3.extensions.nCaptcha.backend.Captcha;
import com.nulldev.util.web.HttpServer3.pages.v3.HttpPage3.Request;

public class ImageTextCaptcha implements Captcha {

	@Override
	public DataSet<String, String[]> generateBase64Image(final int botLevel, final Request request) {
		final String word = StringsUtil.randomString(6);
		final BufferedImage obf = TextObf.obfuscate(word, (botLevel > 1 ? ObfuscationMethod.PixelsAndNoise : ObfuscationMethod.RainbowBackgroundPixels),
				TextObf.__font(BASE_TEXT_SIZE));
		final String base64 = ImageUtil.encodeToString(obf, "png");
		return new DataSet<String, String[]>("data:image/png;base64," + base64, new String[]
			{ word });
	}

	@Override
	public String getType() {
		return "screenwords";
	}
}
